﻿using UnityEngine;
using UnityEngine.UIElements;

namespace winS.UnityEditor.UIElement
{
    public class ColorField : EditorField<Color>
    {
        private readonly global::UnityEditor.UIElements.ColorField colorField;

        internal ColorField(ElementFactory elementFactory) : base(elementFactory)
        {
            Add(colorField = new global::UnityEditor.UIElements.ColorField());
            EditorElementUtility.ApplySubFieldStyle(colorField);
            colorField.RegisterValueChangedCallback(OnValueChangedCallback);
        }

        public override void SetValueWithoutNotify(Color value)
        {
            base.SetValueWithoutNotify(value);
            colorField.SetValueWithoutNotify(value);
        }

        protected override void SetValue(Color value)
        {
            base.SetValue(value);
            colorField.SetValueWithoutNotify(value);
        }

        private void OnValueChangedCallback(ChangeEvent<Color> changeEvent)
        {
            base.SetValue(changeEvent.newValue);
        }
    }
}